/*
 *  Copyright (C) 2012 Компания ВИТ. web: http://diasled.ru Е-mail:  vit@diasled.ru
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ru.apertum.diasled.model.exam;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Set;
import javax.swing.tree.TreeNode;
import ru.apertum.diasled.model.Examination;

/**
 *
 * @author Evgeniy Egorov, Aperum Projects
 */
public class TypeShoesNode extends AExamNode {

    @Override
    public String toString() {
        return name;
    }
    final private String name;

    public String getName() {
        return name;
    }
    final private TreeNode root;
    final private Set<Examination> nodes;
    final public HashMap<Integer, InsideElementNode> elemsNodeAll = new HashMap<>();
    final private LinkedList<TreeNode> elemsVisible = new LinkedList<>();

    @Override
    public LinkedList<TreeNode> getVisibleChildren() {
        return elemsVisible;
    }

    public TypeShoesNode(String shoesName, RootNodeExam root, Set<Examination> nodes) {
        name = shoesName;
        this.root = root;
        this.nodes = nodes;
        createChildren();
    }

    private void createChildren() {
        for (String elemName : InsideElements.getInstance().getItems()) {
            final InsideElementNode node = new InsideElementNode(elemName, this, nodes);
            elemsNodeAll.put(InsideElements.getInstance().getIdByStr(elemName),  node);
            for (Examination exam : nodes) {
                if (exam.getShoesType() == Shoes.getInstance().getIdByStr(name)
                        && exam.getInsideElement() == InsideElements.getInstance().getIdByStr(elemName)) {
                    elemsVisible.add(node);
                    break;
                }
            }
        }
    }

    @Override
    public TreeNode getParent() {
        return root;
    }
    /*
    public void addExam(Examination exam) {
    elemsNodeAll.clear();
    elemsVisible.clear();
    createChildren();
    for (TreeNode n : elemsVisible) {
    final InsideElementNode node = (InsideElementNode) n;
    node.addExam(exam);
    }
    }
     * 
     */
}
